<template>
  <div>
    <div class="printOrder">
      <!-- <el-row>
        <el-col :span="24">
          <label class="durg_title">申领详情</label>
        </el-col>
      </el-row> -->
      <el-page-header @back="goBack" :content="detail.title">    
      </el-page-header>
      <br />
      <br />
      <el-row>
        <el-row>
          <el-col :span="4">领用科室：{{ detail.departmentName }}</el-col>
          <el-col :span="4">领用医生：{{ detail.doctorName }}</el-col>
          <el-col :span="4">经手人：{{detail.operatorName }}</el-col>
          <el-col :span="4">申领日期：{{detail.applyDate }}</el-col>
          <el-col v-if="detail.status==1" :span="4">出库日期：{{detail.outStockDate }}</el-col>
          <el-col v-if="detail.status==2" :span="4">拒绝理由：{{detail.denialReason?detail.denialReason:'无'}}</el-col>
        </el-row>
        <br />
        <el-col :span="24">
          <el-table :data="detail.list">
            <el-table-column prop="id" label="序号" width="180"></el-table-column>
            <el-table-column prop="drugName" label="药品名称" width="180"> </el-table-column>
            <el-table-column prop="spec" label="规格" width="180"></el-table-column>
            <el-table-column prop="applyNum" label="申请数量" width="180"> </el-table-column>
            <el-table-column label="单位" >
               <template slot-scope="scope">
                 {{scope.row.applyUnit | changeAssist(dwList)}}
                </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
    </div>
    <br />
    <span slot="footer">
      <el-button v-if="detail.status == 0" type="primary" @click="onCancel">取消申领</el-button>
    </span>
  </div>
</template>
<script>
import Valid from "@/_js/validate.js";
import enumArr from "../_enum";
export default {
  data() {
    return {
      btnLoading: false,
      detail: "",
      dwList: [],
      durg_id: "",
      statusList: enumArr.status,
    };
  },
  mounted() {
    this.verifyUrlAttack(this.$route.query).then(() => {
      this.durg_id = this.jieMi(this.$route.query.id);
      this.getDetail();
      this.getBasicData();
    });
  },
  methods: {
    getDetail() {
      this.$api.getDrugApplyLogById({ id: this.durg_id }).then((res) => {
        if (res.executed) {
          this.detail = res.dataBody;
          this.detail.title='申领详情-'+this.$utils.getEunmValue(this.detail.status,this.statusList);
        }
      });
    },
    onClose() {
      let th = this;
      let type = th.$route.query.type;
      this.addNavMenu("药品库", "/page/drugIndex");
      this.$router.push({
        path: "/page/drugIndex",
        query: this.getUrlToken({ id: this.jiaMi(1) }),
      });
    },
    //获取通用配置
    getBasicData() {
      this.getCommonConfigByKey("药品剂量单位").then((res) => {
        this.dwList = res;
      });
    },
    onCancel() {
      this.$confirm("您确定要取消申请吗", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      }).then(() => {
          this.$api.cancelApply({ id:this.durg_id }).then((res) => {
            if(res.executed){
              this.$message.success(res.message);
              this.getDetail();
            }else{
              this.$message.success(res.message);
            }
          });
        }).catch(() => {});
    },
    //返回上一级
    goBack() {
      this.$router.go(-1);
    },
  },
  components: {},
};
</script>
<style lang="scss" scoped>
.durg_title {
  display: inline-block;
  width: 100%;
  font-size: 16px;
  border-bottom: 1px solid #ddd;
  padding-bottom: 10px;
  margin-bottom: 10px;
}
.durg_form {
  .el-input,
  .el-select {
    width: 90%;
  }
  .el-form-item__label {
    padding-bottom: 0;
  }
  .one_dose_select {
    width: 30%;
    position: absolute;
    right: 28px;
  }
}
</style>
